package com.example.mapper;

import com.example.domain.dto.QuestionDTO;
import com.example.domain.po.AnswerRecord;
import com.example.domain.po.QuestionType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    @Select("SELECT * FROM question " +
            "ORDER BY RAND() " +
            "LIMIT 50 ")
    List<QuestionDTO> listByRandom();

    @Insert("insert into answer_record values " +
            "(null,#{uid},#{score},now())")
    void record(@Param("uid") Integer uid, @Param("score") String score);

    List<AnswerRecord> listRecordByUid(Integer uid);

    @Select("SELECT * FROM question " +
            "where qtype_id =#{qTypeId} " +
            "ORDER BY RAND() " +
            "LIMIT 50 ")
    List<QuestionDTO> listByQTypeId(Integer diseaseId);

    List<QuestionDTO> list(@Param("topic") String topic,@Param("type") Integer type, @Param("qtypeId") Integer qtypeId);

    @Select("select * from question_type ")
    List<QuestionType> listQuestionType();

    @Select("select * from question " +
            "where id = #{id} ")
    QuestionDTO getById(Integer id);

    void edit(QuestionDTO questionDTO);

    @Insert("insert into question values " +
            "(null,#{topic},#{a},#{b},#{c},#{d},#{e},#{answer},#{type},#{pic},#{analysis},#{qtypeId})")
    void insert(QuestionDTO questionDTO);

    @Delete("delete from question " +
            "where id = #{id}")
    void deleteById(Integer id);

    @Select("select * from question ")
    List<QuestionDTO> listALl();
}
